package com.code2roc.fastboot.system.setting.service.impl;

import com.code2roc.fastboot.framework.security.ISecurityConfigHandleService;
import com.code2roc.fastboot.framework.util.ConvertOp;
import com.code2roc.fastboot.system.setting.bizlogic.ConfigLogic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class SecurityConfigHandleService implements ISecurityConfigHandleService {
    @Autowired
    private ConfigLogic configLogic;

    @Override
    public List<String> getAllowedOrigin() {
        return Arrays.asList(configLogic.getConfigValueByName("AllowedOrigin").split("\\@"));
    }

    @Override
    public List<String> getAllowAnonymousAccess() {
        return Arrays.asList(configLogic.getConfigValueByName("AllowAnonymousAccess").split("\\@"));
    }

    @Override
    public boolean isOpenXSS() {
        return configLogic.getConfigValueByName("OpenXSS").equals("10");
    }

    @Override
    public boolean isOpenSQLInject() {
        return configLogic.getConfigValueByName("OpenSQLInject").equals("10");
    }

    @Override
    public int getValidateCodeExpire() {
        return ConvertOp.convert2Int(configLogic.getConfigValueByName("ValidateCodeExpire"));
    }

    @Override
    public int getTokenExpire() {
        return ConvertOp.convert2Int(configLogic.getConfigValueByName("TokenExpire"));
    }
}
